package com.cbgolf.oa.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.ButterKnife;
import com.cbgolf.oa.R;
import com.cbgolf.oa.util.ViewUtils;
import com.cbgolf.oa.widget.autolayout.AutoRelativeLayout;

/**
 * @author lq
 */
public class TopView extends AutoRelativeLayout {

  private View topBack;
  private ImageView topBackIv;
  private View titleView;
  private TextView titleTv;
  private ImageView titleIv;

  private View topRightView;
  private TextView topRightTv;
  private ImageView topRightLeftIv;
  private ImageView topRightRightIv;


  public TopView(Context context) {
    this(context, null);
  }

  public TopView(Context context, AttributeSet attrs) {
    this(context, attrs, 0);

  }

  public TopView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    LayoutInflater.from(context).inflate(R.layout.g_topnew, this);
    topBack = ButterKnife.findById(this, R.id.ll_topback);

    titleView = ButterKnife.findById(this, R.id.ll_toptitle);
    titleTv = ButterKnife.findById(this, R.id.tv_toptitle);
    titleIv = ButterKnife.findById(this, R.id.iv_toptitle);

    topRightView = ButterKnife.findById(this, R.id.ll_topright);
    topRightTv = ButterKnife.findById(this, R.id.tv_topright);
    topRightLeftIv = ButterKnife.findById(this, R.id.iv_topright_tvleft);
    topRightRightIv = ButterKnife.findById(this, R.id.iv_topright_tvright);

  }

  /**
   * 标题
   */
  public void setTitle(CharSequence title) {
    ViewUtils.setText(titleTv, title);
  }

  /**
   * 标题
   */
  public void setRightTvText(CharSequence text) {
    ViewUtils.setText(topRightTv, text);
  }

  /**
   * 标题 imageview
   *
   * @param imageRes 标题图标
   */
  public void setTitleImage(int imageRes) {
    ViewUtils.setImage(titleIv, imageRes);
  }

  /**
   * title view监听
   */
  public void setTitleViewListener(OnClickListener listener) {
    ViewUtils.setClick(titleView, listener);
  }

  /**
   * 返回监听
   */
  public void setBackListener(OnClickListener listener) {
    ViewUtils.setClick(topBack, listener);
  }

  /**
   * 右边view监听
   */
  public void setTopRightListener(OnClickListener listener) {
    ViewUtils.setClick(topRightView, listener);
  }

  /**
   * 右边textview监听
   */
  public void setTopRightTvListener(OnClickListener listener) {
    ViewUtils.setClick(topRightTv, listener);
  }

  /**
   * 右边----文字 左边 imageview监听
   */
  public void setTopRightLeftIvListener(OnClickListener listener) {
    ViewUtils.setClick(topRightLeftIv, listener);
  }

  /**
   * 右边----文字 右边 imageview监听
   */
  public void setTopRightRightIvListener(OnClickListener listener) {
    ViewUtils.setClick(topRightRightIv, listener);
  }

  public void setTopRightViewVisible(boolean visible) {
    ViewUtils.setVisible(topRightView, visible);
  }

  /**
   * 标题栏右边包括三个控件，topRightLeftIv,topRightTv,topRightRightIv
   * 初始状态都为隐藏
   * 以topRightTv为准，一边一个ImageView ，根据UI选择显示哪个
   *
   * 显示/隐藏 左边那个imageview
   *
   * @param visible 显示/隐藏
   */
  public void setTopRightLeftIvVisible(boolean visible) {
    setTopRightVisible(visible);
    ViewUtils.setVisible(topRightLeftIv, visible);
  }

  /**
   * 标题栏右边包括三个控件，topRightLeftIv,topRightTv,topRightRightIv
   * 初始状态都为隐藏
   * 以topRightTv为准，一边一个ImageView ，根据UI选择显示哪个
   *
   * 设置左边 imageview图标
   */
  public void setTopRightLeftIvImage(int imageRes) {
    ViewUtils.setImage(topRightLeftIv, imageRes);
  }

  /**
   * 标题栏右边包括三个控件，topRightLeftIv,topRightTv,topRightRightIv
   * 初始状态都为隐藏
   * 以topRightTv为准，一边一个ImageView ，根据UI选择显示哪个
   *
   * 显示/隐藏 右边那个imageview
   *
   * @param visible 显示/隐藏
   */
  public void setTopRightRightIvVisible(boolean visible) {
    setTopRightVisible(visible);
    ViewUtils.setVisible(topRightRightIv, visible);
  }

  /**
   * 标题栏右边包括三个控件，topRightLeftIv,topRightTv,topRightRightIv
   * 初始状态都为隐藏
   * 以topRightTv为准，一边一个ImageView ，根据UI选择显示哪个
   *
   * 设置右边 imageview图标
   */
  public void setTopRightRightIvImage(int imageRes) {
    ViewUtils.setImage(topRightRightIv, imageRes);
  }

  /**
   * 显示/隐藏 右边textview
   */
  public void setTopRightTvVisible(boolean visible) {
    setTopRightVisible(visible);
    ViewUtils.setVisible(topRightTv, visible);
  }

  private void setTopRightVisible(boolean visible) {
    if (visible) {
      ViewUtils.setVisible(topRightView, visible);
    }
  }

}
